package com.hjyang.docx.convert.pdf.controller;

import com.gsafety.fileauxiliarysystem.exception.Result;
import com.gsafety.fileauxiliarysystem.utils.StringUtil;
import com.gsafety.fileauxiliarysystem.utils.doc.conver.DocxToPdf;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/conver/word2pdf")
public class Docx2PdfController {
    /**
     * docx转Pdf
     * @param wordFilePath
     * @param pdfFilePath
     * @return
     */
    @RequestMapping(value = "/docx", method = RequestMethod.POST)
    public Result word2pdf(String wordFilePath, String pdfFilePath) {
        if ("".equals(StringUtil.null2String(wordFilePath))) {
            return new Result(400, "参数 wordFilePath 为空");
        }
        if ("".equals(StringUtil.null2String(pdfFilePath))) {
            return new Result(400, "参数 pdfFilePath 为空");
        }
        String word2pdfStr = DocxToPdf.word2pdf(wordFilePath, pdfFilePath);
        if ("pdf".equals(word2pdfStr)) {
            return new Result(200, "success");
        } else {
            return new Result(400, "Word转Pdf失败！");
        }
    }
}
